#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"

service-app-links-cmd() {
  #E list all $PLUGIN_COMMAND_PREFIX services that are linked to the 'playground' app.
  #E dokku $PLUGIN_COMMAND_PREFIX:app-links playground
  #A app, app to run command against
  declare desc="list all $PLUGIN_SERVICE service links for a given app"
  local cmd="$PLUGIN_COMMAND_PREFIX:app-links" argv=("$@")
  [[ ${argv[0]} == "$cmd" ]] && shift 1
  declare APP="$1"
  APP=${APP:="$DOKKU_APP_NAME"}

  [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
  verify_app_name "$APP"
  service_app_links "$APP"
}

service-app-links-cmd "$@"
